/*
 * TiffCompressionLogLuv
 *
 * Copyright (c) 2002, 2003 Marco Schmidt.
 * All rights reserved.
 * 
 * translated to C# and updated by asida
 * 
 * Copyright (c) Adam Sida, asida@centrum.cz
 * All rights reserved.
 */
using System;

namespace Petra.Gis.ImagingServices.Tiff
{
  ///<summary>
  /// A TIFF decoder for files compressed with the <em>LogLuv RLE</em> method.
  /// This compression algorithm has the value <code>34676</code> 
  /// ({@link TIFFConstants#COMPRESSION_SGI_LOG_RLE})
  /// in the compression tag of an image file directory.
  /// Only image data with a photometric interpretation value of 
  /// {@link TIFFConstants#PHOTOMETRIC_TRUECOLOR_LOGLUV} can be compressed with this method.
  /// <p>
  /// This implementation is based on the file <code>tif_luv.c</code> which
  /// is part of the TIFF library <a target="_top" href="http://www.libtiff.org">libtiff</a>.
  /// The original implementation was written by Greg W. Larson.
  /// <p>
  /// Learn more about the color type and its encoding on Greg's page
  /// <a target="_top" href="http://positron.cs.berkeley.edu/~gwlarson/pixformat/tiffluv.html">LogLuv 
  /// Encoding for TIFF Images</a>.
  /// You will also find numerous sample image files there.
  /// @author Marco Schmidt
  /// @since 0.10.0
  ///</summary>
  public class TiffCompressionLogLuv : Compression
  {


    public TiffCompressionLogLuv()
      : base() { }




    //public TiffCompressionLogLuv(TiffBitmapPage currImage)
    //  : base(currImage){ }




    //public static override Compression CreateCompressionInstance(BlockBitmapSource image)
    //{
    //  return new TiffCompressionLogLuv(image);
    
    //}



    //private DataInput din;
    private int compressedSize;
    //private int tileWidth;
    private bool _isRle;

    public override byte[] DecompressBlock(BitmapBlock block, byte[] comprData, int srcBitsPerSample)
    {
      //if (_image == null)
      //  throw new InvalidOperationException("no image presents to decompress");


      return null;
    }

    private void decodeRow(byte[] row)
    //throws		InvalidFileStructureException,		IOException
    {
      if (_isRle)
      {
        decodeRowRLE(row);
      }
      else
      {
        decodeRowPacked24(row);
      }
    }




    private void decodeRowPacked24(byte[] row)
    {
      //int num = _currBlock.Width * 3;
      //row = _tiffReader.ReadBytes(num);
    }




    private void decodeRowRLE(byte[] row)
    {
      //int BYTES_PER_PIXEL;
      //if (_image.TiffMetadata.PhotometricInterpretation == PhotometricType.LOGL)
      //{
      //  BYTES_PER_PIXEL = 2; // LogL
      //}
      //else
      //{
      //  BYTES_PER_PIXEL = 4; // LogLuv
      //}
      //for (int initialOffset = 0; initialOffset < BYTES_PER_PIXEL; initialOffset++)
      //{
      //  int offset = initialOffset;
      //  int numPixels = _currBlock.Width;
      //  do
      //  {
      //    int v1 = _tiffReader.ReadByte();
      //    if ((v1 & 128) != 0)
      //    {
      //      // run
      //      int runCount = v1 + (2 - 128);
      //      numPixels -= runCount;
      //      compressedSize -= 2;
      //      byte v2 = _tiffReader.ReadByte();
      //      while (runCount-- != 0)
      //      {
      //        row[offset] = v2;
      //        offset += BYTES_PER_PIXEL;
      //      }
      //    }
      //    else
      //    {
      //      // non-run, copy data
      //      int runCount = v1;
      //      numPixels -= runCount;
      //      compressedSize = compressedSize - runCount - 1;
      //      while (runCount-- != 0)
      //      {
      //        row[offset] = _tiffReader.ReadByte();
      //        offset += BYTES_PER_PIXEL;
      //      }
      //    }
      //    if (compressedSize < 0)
      //    {
      //      throw new InvalidFileStructureException("Ran out of compressed input bytes before completing the decoding process.");
      //    }
      //  }
      //  while (numPixels > 0);
      //}
    }


    /// <summary>
    /// returns supported compression types
    /// </summary>
    public override CompressionType[] CompressionTypes
    {
      get {
        return new CompressionType[] { CompressionType.SGILOG, 
                                       CompressionType.SGILOG24 }; 
      }
    }

  }
}